package demo2;

public class Computer{
    public void Openco(){
        System.out.println("打开电脑");
    }
    public void Closeco(){
        System.out.println("关闭电脑");
    }

    public void useDevice(USB usb){
        usb.OpenDevice();
        if (usb instanceof KeyBoard){
            KeyBoard keyBoard = (KeyBoard)usb;
            keyBoard.input();//向上转型
        } else if (usb instanceof  Mouse) {
            Mouse mouse = (Mouse)usb;
            mouse.click();//向上转型
        }

        usb.CloseDevice();
    }
}
